package io.renren.modules.car.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.car.entity.CarFriendShopEntity;
import io.renren.modules.car.service.CarFriendShopService;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;



/**
 * 合作商家基本信息
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-09-18 09:11:58
 */
@RestController
@RequestMapping("car/carfriendshop")
public class CarFriendShopController extends AbstractController {
    @Autowired
    private CarFriendShopService carFriendShopService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("car:carfriendshop:list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("create_user",getUserIdInt());
        PageUtils page = carFriendShopService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("car:carfriendshop:info")
    public R info(@PathVariable("id") Integer id){
        CarFriendShopEntity carFriendShop = carFriendShopService.getById(id);

        return R.ok().put("carFriendShop", carFriendShop);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("car:carfriendshop:save")
    public R save(@RequestBody CarFriendShopEntity carFriendShop){
        Date date = new Date();
        carFriendShop.setCreateTime(date);
        carFriendShop.setUpdateTime(date);
        carFriendShop.setCreateUser(getUserIdInt());
        carFriendShopService.save(carFriendShop);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("car:carfriendshop:update")
    public R update(@RequestBody CarFriendShopEntity carFriendShop){
        ValidatorUtils.validateEntity(carFriendShop);
        carFriendShop.setUpdateTime(new Date());
        carFriendShopService.updateById(carFriendShop);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("car:carfriendshop:delete")
    public R delete(@RequestBody Integer[] ids){
        carFriendShopService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
